<?php
//
// +------------------------------------------------------------------------+
// | Gecko Framework                                                        |
// +------------------------------------------------------------------------+
//
require_once("Gecko/Form/Exception.php");
require_once("Gecko/Form/Field.php");
require_once("Gecko/DataSource/Select/SQL.php");

/**
 * Select control with a SQL Source
 *
 * @package Gecko.Form.Field;
 * @author Christopher Valderrama <valderrama.christopher@gmail.com>
 * @copyright Copyright (c) 2008
 * @version $Id$v1.0$ 2008
 * @access public
 **/
class Gecko_Form_Field_SelectSQL extends Gecko_Form_Field_Select {
	/**
	 * Creates a new SQL Select control, a sql, and db params are
	 * expected in the $params array
	 *
	 * @param string $name
	 * @param string $value
	 * @param array $params
	 */
	public function __construct( $name, $value = "", $params = array() ) {
		parent::__construct( $name, $value, $params );

		$db = (isset( $params['db'] ) ? $params['db'] : null );
		$sql = (isset( $params['sql'] ) ? $params['sql'] : null );

		if( !( $db instanceof Zend_Db_Adapter ) ) {
			throw new Gecko_Form_Exception( '$db isn\'t initialized, please set it in $params' );
		}

		if( !$sql ) {
			throw new Gecko_Form_Exception( '$sql not set' );
		}

		$source = new Gecko_DataSource_Select_SQL( $db, $sql );
		$this->setSource( $source );
	}
}